package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Orderdetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderdetailMapper {
    // 查询全部订单详情
    @Select("SELECT * FROM orderdetail")

    List<Orderdetail> findAll();

    // 根据id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE id = #{id}")

    Orderdetail findById(int id);

    // 根据订单id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE orderid = #{orderid}")

    List<Orderdetail> findByOrderid(int id);

    // 根据商品id查询订单详情
    @Select("SELECT * FROM orderdetail WHERE productid = #{productid}")

    List<Orderdetail> findByProductid();

    // 插入订单详情
    @Insert("INSERT INTO orderdetail(orderid, productid, count) VALUES(#{orderid}, #{productid}, #{count})")
    int insertOrderdetail(Orderdetail orderdetail);

    // 更新订单详情
    @Update("UPDATE orderdetail SET orderid=#{orderid}, productid=#{productid}, count=#{count} WHERE id=#{id}")

    int updateOrderdetailById(Orderdetail orderdetail);

    // 删除订单详情
    @Delete("DELETE FROM orderdetail WHERE id=#{id}")

    int deleteOrderdetailById(int id);
}